# TODO 导入base模块
from common.base import Base, By
from page.login_page import LoginPage
from selenium.webdriver.support.ui import Select
from common.functions import browser_operation

class ReceivingAddressPage(Base):
    # TODO 当前页面路径
    # ReceivingAddress_url = 'http://172.16.140.55/ecshop/user.php?act=address_list'

    # TODO 点击：用户中心，进入该页面
    def into_user_center(self):
        self.click((By.LINK_TEXT,'用户中心'))

    # 隐式等待


    # TODO 定位：用户中心框架：class="userMenu “
    def location_user_center(self):
        frame = self.find_element((By.CLASS_NAME,'userMenu'))
        self.driver.switch_to.frame(frame)

    # TODO 点击：收货地址 按钮：class="curs"/html/body/div[6]/div[1]/div/div/div/div/a[4]
    def btn_receiving_address(self):
        self.click((By.XPATH,'/html/body/div[6]/div[1]/div/div/div/div/a[4]'))

    # TODO 定位：收货人信息框架：class="box"
    def receiving_user_info(self):
        self.driver.switch_to.frame('box')

    # 带*为必填信息，下拉框：select.select_by_value(value)
    # TODO 定位：*请选择省 下拉定位：name="province"
    '''
    def select_province(self,province_name):
        # 创建select对象
        s1 = self.click((By.NAME,'province'))
        select = Select(s1)
    # 选择 option
        select.select_by_value(province_name)

    '''
    def select_province(self, index):
        # 创建select对象
        s1 = self.find_element((By.TAG_NAME, 'select')[1])
        select = Select(s1)
        # 选择 option
        select.select_by_index(index)

    # TODO 定位：*请选择市 下拉定位：name="city"
    def select_city(self,city_name):
        # 创建select对象
        s1 = self.click((By.NAME,'city'))
        select = Select(s1)
    # 选择 option
        select.select_by_value(city_name)

    # TODO 定位：*收货人姓名：class="inputBg"
    def consignee_name(self,cons_name):
        consignee = self.click((By.CLASS_NAME,'inputBg'))
        consignee.send.keys(cons_name)

    # TODO 定位：*详细地址：name="address"
    def detailed_addr(self,det_addr):
        address = self.click((By.CLASS_NAME, 'address'))
        address.send.keys(det_addr)

    # TODO 定位：电话：name="tel"
    def telephone(self,tel):
        telephone = self.click((By.CLASS_NAME, 'tel'))
        telephone.send.keys(tel)

    # TODO 定位：*电子邮件地址：name="email"
    def email_addr(self,email):
        email_addr = self.click((By.CLASS_NAME, 'email'))
        email_addr.send.keys(email)

    # TODO 定位：邮政编码：name = "zipcode"
    def postal_code(self,post_num):
        code = self.click((By.CLASS_NAME, 'zipcode'))
        code.send.keys(post_num)

    # TODO 定位：手机：name="mobile"
    def mobile_phone(self,phone_number):
        mobile_phone = self.click((By.CLASS_NAME, 'mobile'))
        mobile_phone.send.keys(phone_number)

    # TODO 定位：新增收货地址 按钮：name="submit"
    def add_receiving_address(self):
        self.click((By.CLASS_NAME, 'submit'))

if __name__ == '__main__':
    driver = browser_operation()
    login = LoginPage(driver)
    addr = ReceivingAddressPage(driver)
    login.get_website('http://172.16.140.55/ecshop/user.php')
    login.input_username('豆芽纸')
    login.input_password('123456')
    login.btn_login()



    # 调用：新增收货地址流程
    # addr.location_user_center()
    addr.implicitly_wait()


    addr.btn_receiving_address()
    # addr.receiving_user_info()
    addr.select_province(3)
    addr.select_city('武汉市')
    addr.consignee_name('豆芽纸')
    addr.detailed_addr('湖北省武汉市洪山区曙光星城A区')
    addr.telephone('027-28865253')
    addr.email_addr('462562662@qq.com')
    addr.postal_code('410009')
    addr.mobile_phone('12412345678')

    addr.add_receiving_address()
    """ """